package S15.first;

import java.util.Arrays;
import java.util.Comparator;

public class F01 {

	public static void main(String[] args) {
		String saying="Practice makes perfect"; //熟能生巧
		String[]ss=saying.split(" "); //获得字符串数组
		// String[]ss={"Practice", "makes", "perfect"};
		System.out.println("流中原来的数据：");
		Arrays.stream(ss).forEach(s->System.out.println(s));
		System.out.println("流中的元素转换为大写：");
		Arrays.stream(ss).map(s->s.toUpperCase()).forEach(s->System.out.println(s));
		System.out.println("流中每个字符串的长度：");
		Arrays.stream(ss).map(s->s.length()).forEach(s->System.out.println(s));
		System.out.println("流中字符串长度小于8的：");
		Arrays.stream(ss).filter(s->s.length()<8).forEach(s->System.out.println(s));
		System.out.println("流中字符串中含有字符r的单词有：");
		Arrays.stream(ss).filter(s->s.indexOf('r')>=0).forEach(s->System.out.println(s));
		
		saying="You can see the sea but you can not see the sea";
		ss=saying.split(" ");
		System.out.println("流中原来的数据：");
		Arrays.stream(ss).forEach(s->System.out.print(s+", "));
		System.out.println("\n去除流中相同的单词：");
		Arrays.stream(ss).distinct().forEach(s->System.out.print(s+", "));
		System.out.println("\n去除流中相同的单词，忽略大小写：");
		Arrays.stream(ss).map(s->s.toLowerCase()).distinct().forEach(s->System.out.print(s+", "));
		System.out.println("\n流中单词(去重)从小大到大排序输出：");
		Arrays.stream(ss).distinct().sorted().forEach(s->System.out.print(s+", "));
		System.out.println("\n流中单词(去重)从大到小排序输出：");
		Arrays.stream(ss).distinct()
			.sorted(Comparator.comparing(s->s, Comparator.reverseOrder()))
			.forEach(s->System.out.print(s+", "));
	}

}
